<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>如何显示数字时钟的格式时间</title>
    
</head>
<body>
    <script type="text/javascript">
        // 0:00:00 P.M 
        function nowNumTime(){
            var now = new Date();
            timeStr = now.toLocaleTimeString();
            // console.log(timeStr);

            var hour = now.getHours();
            var minute = now.getMinutes();
            var second = now.getSeconds();
            var temp = '';
            temp = '' + (hour > 12 ? hour-12 : hour);
            if(hour === 0){
                temp = '12';
            }
            minute = (minute < 10 ? ':0' : ':') + minute;
            second =  (second < 10 ? ':0' : ':') + second;
            temp = temp + minute + second + (hour >= 12 ? ' P.M.' : ' A.M.');
            
            return temp;
        }
        var time = nowNumTime();
        console.log(time);
    </script>
</body>
</html>